package cn.moukou.dictator.util;

import cn.moukou.dictator.pojo.StudentOrganization;
import org.neo4j.ogm.typeconversion.CompositeAttributeConverter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class StudentOrganizationConverter implements CompositeAttributeConverter<StudentOrganization> {

    @Override
    public Map<String, ?> toGraphProperties(StudentOrganization entity) {
        Map<String, Object> properties = new HashMap<>();
        if (entity != null)  {
            properties.put("student_organization_name", entity.getName());
            properties.put("student_organization_total_num", entity.getTotalNum());
            properties.put("student_organization_description", entity.getDescription());
            properties.put("student_organization_member_list", entity.getMemberList());
        }
        return properties;
    }

    @Override
    public StudentOrganization toEntityAttribute(Map<String, ?> map) {
        if(!map.get("node_type").toString().equals("student_organization")) {
            return null;
        }
        StudentOrganization entity = new StudentOrganization();
        entity.setName((String) map.get("student_organization_name"));
        entity.setTotalNum((String) map.get("student_organization_total_num"));
        entity.setDescription((String) map.get("student_organization_description"));
        entity.setMemberList((List<String>) map.get("student_organization_member_list"));

        return entity;
    }
}
